﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using DG.Tweening;
public class CubeCollider : MonoBehaviour {

    GameObject effectGo;
    public static bool cllid = false;
    AudioSource audioSource;
    GameObject toast;
    void Start()
    {
        toast = GameObject.Find("Toast").transform.Find("Msg").gameObject;
        audioSource = GetComponent<AudioSource>();
    }

    void DestoryEffect()
    {
        Destroy(effectGo);
    }

    void OnTriggerEnter(Collider col)
    {
        Debug.Log("enter");
        audioSource.Play();
        cllid = true;
        effectGo = Instantiate(Resources.Load("Prefab/Effect/Particle System"), transform.position, transform.rotation) as GameObject;
        Toast("");
        Invoke("DestoryEffect", 3f);
    }
    
    void Toast(string msg)
    {
        Text t = toast.GetComponent<Text>();
        toast.SetActive(true);
        t.text = "your " + gameObject.name + " hitted";
        Invoke("HideToast", 3f);
    }

    void HideToast()
    {
        toast.SetActive(false);
    }
}
